package cn.wolfcode.crm.web.controller;


import cn.wolfcode.crm.domain.Dictionary;
import cn.wolfcode.crm.qo.PageResult;
import cn.wolfcode.crm.qo.QueryObject;
import cn.wolfcode.crm.service.IDictionaryService;
import cn.wolfcode.crm.util.JSONResult;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("dictionary")
public class DictionaryController {
    @Autowired
    private IDictionaryService dictionaryService;


    //查询所有字典目录
    @RequestMapping("query")
    @ResponseBody
    public Object selectAll() {
        //将数据转换成json格式
        List<Dictionary> dictionarys = dictionaryService.selectAll();

        return dictionarys;
    }



    @RequestMapping("view")

    public String list1(Model model, Long id) {

        return "/dictionary/list";
    }




    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate( Dictionary entity) {
       dictionaryService.saveOrUpdate(entity);

        return new JSONResult();
    }



    @RequestMapping("delete")
    @ResponseBody
    public Object delete( Long id) {
       dictionaryService.deleteByPrimaryKey(id);

        return new JSONResult();
    }


}
